package com.example.cloud.config;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

import com.example.cloud.util.spring.SpringContextUtils;

/**
 * 工具类自动初始化成Spring Bean
 *
 * @author tongyufu
 * @since 2018年11月16日 下午6:00:36
 */
@Configuration
public class UtilsAutoConfig {

    /**
     * ApplicationContext工具类
     *
     * @param applicationContext applicationContext
     * @return SpringContextUtils
     */
    @Order(Ordered.HIGHEST_PRECEDENCE)
    @Bean
    @ConditionalOnMissingBean
    @Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON)
    public SpringContextUtils springContextUtils(ApplicationContext applicationContext) {
        return new SpringContextUtils(applicationContext);
    }

}
